<template>
  <el-dialog :title='titleFont' :visible.sync='isShow' width='700px' :lock-scroll=false :close-on-click-modal=false @close='clearForm("queryForm")' @open="openInitializtaion">
    <div v-loading="loading">
      <el-card class='type-info-box-card'>
        <el-form ref='queryForm' size='mini' :model="queryForm" label-width="140px" :rules="rules" label-position="top">
          <el-row :gutter="30">
            <!-- <el-col :md='12' :lg='12'>
              <el-form-item label='机构号' prop='BRANCH'>
                <select-tree ref="tree" :single-check="true" v-model="queryForm.BRANCH" :props='{id:"branchId",label: "branchName",children: "childBranch"}' :tree-data="brno">
                </select-tree>
              </el-form-item>
            </el-col> -->
            <el-col :md='12' :lg='12'>
              <el-form-item label='柜员号' prop='AGENTID'>
                <!-- <el-input v-model='queryForm.AGENTID' ></el-input> -->
                <el-select v-model='queryForm.AGENTID' filterable>
                  <el-option v-for='item in AGENTIDS' :key='item.AGENTID' :label='item.AGENTNAME' :value='item.AGENTID'>
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <!-- <el-col :md='12' :lg='12'>
                <el-form-item label='维护人员' prop='ACCENDANT'>
                  <el-input v-model='queryForm.ACCENDANT'></el-input>
                </el-form-item>
              </el-col>
              <el-col :md='12' :lg='12'>
                <el-form-item label='维护日期' prop='OPERDATE'>
                  <el-date-picker v-model='queryForm.OPERDATE' value-format='yyyyMMdd' type='date' placeholder='选择日期'>
                  </el-date-picker>
                </el-form-item>
              </el-col> -->
          </el-row>
          <el-row :gutter="30">
            <el-col :span='100'>
              <el-form-item label='交易名称' prop='TransactionArr'>
                <el-transfer filterable :props="{label: 'FLOWNAME', key:'FLOWID'}" :data="FLOWNAMEOpions" v-model="queryForm.TransactionArr"></el-transfer>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
      <div slot="footer" style="margin:10px 0;text-align:center">
        <el-button size="mini" @click="isShow=false">取消</el-button>
        <el-button type='primary' size='mini' @click="submit">确定</el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
  import DateUtils from '@/CTManage/utils/DateUtils';
  import request from "@/common/utils/requestCT";
  import selectTree from "@/components/selectTree2/";
  import getGlobalParams from '@/common/utils/getGlobalParams';
  import spinnerList from "@/message/spinnerDataQuery/spinner-data-query";
  import transactionNameQuery from "@/message/shared/transaction-name-query";
  import cloudExceptionTran from "@/message/CTManage/cloud-exception-transaction/cloud-exception-transaction";
  import cloudTellerQuery from "@/message/CTManage/teller/cloud-teller-query";
  export default {
    components: {
      selectTree
    },
    data() {
      return {
        AGENTIDS: [],
        brno: [],
        loading: false,
        titleFont: '柜员对应渠道',
        queryForm: { //表单数据
          BRANCH: [],
          AGENTID: '',
          TransactionArr: []
        },
        FLOWNAMEOpions: [],
        rules: { //表单校验规则
          BRANCH: [{
            required: true,
            message: "请选择渠道名称",
            trigger: "change"
          }],
          AGENTID: [{
            required: true,
            message: "请选择云柜员",
            trigger: "change"
          }],
          TransactionArr: [{
            required: true,
            message: "请选择交易名称",
            trigger: "change"
          }]
        }
      };
    },
    props: {
      option: Object
    },
    methods: {
      queryTeller() {
        let resBody = new cloudTellerQuery();
        resBody.data.branchNo = this.$store.state.user.branchId;
        request(resBody)
          .then(response => {
            if (response.SYS_HEAD.ReturnCode === "000000") {
              this.loading = false;
              this.AGENTIDS = response.RSP_BODY.resultSet;
            } else {
              this.$message({
                type: "error",
                message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
              });
            }
          })
      },
      // 获取交易名称方法
      async transactionNameQuery() {
        this.loading = true;
        this.tableData = [];
        this.tableTotal = 0;
        let resBody = new transactionNameQuery();
        let response = await request(resBody);
        this.loading = false;
        if (response.SYS_HEAD.ReturnCode == "000000") {
          this.FLOWNAMEOpions = response.RSP_BODY.resultSet;
          // console.log(this.FLOWNAMEOpions)
        } else {
          this.$message({
            type: "error",
            message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
          });
        }
      },
      openInitializtaion() {
        this.transactionNameQuery();
        this.queryTeller()
        this.titleFont = '柜员例外交易管理新增';
        // const {
        //   AGENTID,
        //   AGENTNAME,
        //   // CENTERID,
        //   CENTERNAME
        // } = { ...this.option.currentRow
        // }
        // console.log(AGENTID, AGENTNAME)
        // this.queryForm = {
        //   AGENTID,
        //   AGENTNAME,
        //   CENTERID,
        //   CENTERNAME
        // }
        // let resBody = new spinnerList();
        // resBody.data.spinnerList = [{
        //   spinnerName: "branch"
        // }];
        // request(resBody)
        //   .then(response => {
        //     if (response.SYS_HEAD.ReturnCode === "000000") {
        //       this.loading = false;
        //       this.brno = response.RSP_BODY.branchSpinner;
        //     } else {
        //       this.$message({
        //         type: "error",
        //         message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
        //       });
        //     }
        //   })
      },
      submit() {
        this.$refs["queryForm"].validate(valid => {
          if (valid) {
            this.loading = true;
            let resBody = new cloudExceptionTran();
            resBody.data.OPERATE = 'I';//新增传I,修改不传
            resBody.data.AGENTID = this.queryForm.AGENTID;//柜员
            // resBody.data.AGENTNAME = this.queryForm.AGENTNAME;
            resBody.data.BRANCH = this.queryForm.BRANCH[0];//机构
            resBody.data.ACCENDANT = this.$store.state.user.userNo;//维护人
            resBody.data.FLOWTRADE = this.queryForm.TransactionArr.join('|');//交易
            request(resBody)
              .then(response => {
                if (response.SYS_HEAD.ReturnCode === "000000") {
                  this.loading = false;
                  this.$message({
                    type: "success",
                    message: "云柜员例外交易添加成功!"
                  });
                  this.isShow = false;
                  this.$emit("refreshTable");
                } else {
                  this.$message({
                    type: "error",
                    message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
                  });
                  this.loading = false;
                }
              })
              .catch(error => {
                this.loading = false;
                console.log(error);
              });
          }
        });
      },
      clearForm(item) {
        if (this.$refs.queryForm) {
          this.$refs.queryForm.resetFields();
          this.$refs.queryForm.clearValidate();
        }
      }
    },
    computed: {
      isShow: {
        get: function() {
          return this.option.isShow;
        },
        set: function(newValue) {
          this.option.isShow = newValue;
        }
      }
    },
    async created() {}
    // mounted() {
    //   window.addEventListener("scroll", this.handleScroll);
    // }
  };
</script>

<style lang="scss" scope>

</style>
